home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 55
/
Freelog055.iso
/
Bas
/
Educatif
/
A laferme
/
Unit1.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
2003-05-03
|
10KB
|
345 lines
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, Grids, Menus, StdCtrls, Buttons;
type
TForm1 = class(TForm)
Panel1: TPanel;
MainMenu1: TMainMenu;
Rgledujeu1: TMenuItem;
Recommencer1: TMenuItem;
Quitter1: TMenuItem;
StaticText1: TStaticText;
StaticText2: TStaticText;
StaticText3: TStaticText;
RadioGroup1: TRadioGroup;
RadioGroup2: TRadioGroup;
Joueur1: TEdit;
Joueur2: TEdit;
Image1: TImage;
Image2: TImage;
Image3: TImage;
Image4: TImage;
Image5: TImage;
Image6: TImage;
Image7: TImage;
Image8: TImage;
Image9: TImage;
Image10: TImage;
Image11: TImage;
Image12: TImage;
Image13: TImage;
Image14: TImage;
Image15: TImage;
Image16: TImage;
Image17: TImage;
Image18: TImage;
Image19: TImage;
Image20: TImage;
Image21: TImage;
Image22: TImage;
Image23: TImage;
Image24: TImage;
Image25: TImage;
Image26: TImage;
Image27: TImage;
Image28: TImage;
Image29: TImage;
Image30: TImage;
Image31: TImage;
Image32: TImage;
Image33: TImage;
Image34: TImage;
Image35: TImage;
Image36: TImage;
Image37: TImage;
Image38: TImage;
Image39: TImage;
Image40: TImage;
Image41: TImage;
Image42: TImage;
bouton: TBitBtn;
Timer1: TTimer;
StaticText4: TStaticText;
StaticText5: TStaticText;
StaticText6: TStaticText;
Bevel1: TBevel;
procedure debut;
procedure FormActivate(Sender: TObject);
procedure RadioGroup2Click(Sender: TObject);
procedure RadioGroup1Click(Sender: TObject);
procedure fin_jeu;
procedure boutonClick(Sender: TObject);
procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Timer1Timer(Sender: TObject);
procedure Quitter1Click(Sender: TObject);
procedure Recommencer1Click(Sender: TObject);
procedure Rgledujeu1Click(Sender: TObject);
{ DΘclarations privΘes }
public
{ DΘclarations publiques }
end;
var
Form1 : TForm1;
cdeb,cfin,ldeb,lfin,nbrej :integer;
xdeb,xfin,ydeb,yfin :integer;
ncp,nim,njeu,ntemp,nj :integer;
fin :string;
score,nessai,cj,lj :array[0..2] of integer;
cell :array[0..5] of array[0..6] of integer;
nomj :array[0..2] of string;
im :array[0..5] of array[0..6] of Timage;
fond :array[0..1] of Timage;
anim :array[0..9]of Timage;
implementation
uses Unit2;
{$R *.DFM}
procedure Tform1.debut;
{initialisation des composants visuels}
var n,p,q :integer;
begin
timer1.enabled:=false;Rgledujeu1.enabled:=true;
panel1.color:=clnavy;fin:='non';
radiogroup1.itemIndex:=-1;radiogroup1.enabled:=false;
radiogroup2.itemIndex:=-1;radiogroup2.enabled:=true;
joueur1.enabled:=false;joueur2.enabled:=false;
statictext1.caption:='Joueur :';statictext2.caption:='Score :';
statictext3.caption:='Essais numΘro :';statictext6.visible:=false;
statictext4.visible:=false;statictext5.visible:=false;
bouton.caption:=' Jeu!';bouton.enabled:=false;
for n:=1 to 5 do
begin
for p:=1 to 6 do
begin
im[n][p].enabled:=true;im[n][p].visible:=true;
q:=(6*(n-1)+p) mod 10;
im[n][p].picture:=anim[q].picture;cell[n][p]:=0;
end;
end;
panel1.enabled:=false;
end;
procedure TForm1.FormActivate(Sender: TObject);
{remplir le tableau d'images}
begin
im[1][1]:=image1;im[1][2]:=image2;im[1][3]:=image3;
im[1][4]:=image4;im[1][5]:=image5;im[1][6]:=image6;
im[2][1]:=image7;im[2][2]:=image8;im[2][3]:=image9;
im[2][4]:=image10;im[2][5]:=image11;im[2][6]:=image12;
im[3][1]:=image13;im[3][2]:=image14;im[3][3]:=image15;
im[3][4]:=image16;im[3][5]:=image17;im[3][6]:=image18;
im[4][1]:=image19;im[4][2]:=image20;im[4][3]:=image21;
im[4][4]:=image22;im[4][5]:=image23;im[4][6]:=image24;
im[5][1]:=image25;im[5][2]:=image26;im[5][3]:=image27;
im[5][4]:=image28;im[5][5]:=image29;im[5][6]:=image30;
fond[0]:=image31;fond[1]:=image32;anim[0]:=image33;
anim[1]:=image34;anim[2]:=image35;anim[3]:=image36;
anim[4]:=image37;anim[5]:=image38;anim[6]:=image39;
anim[7]:=image40;anim[8]:=image41;anim[9]:=image42;
debut;
end;
procedure TForm1.RadioGroup2Click(Sender: TObject);
{pour retourner une image, on clique sur le panel;il faut donc dΘfinir
les images qui correspondent aux coordonnΘes du panel. Ensuite placer les
dos des cartes en fonction du choix de jeu , donner des valeurs au
tableau cell qui contient les numΘros d'images et mΘlanger au hasard
ces numΘros donc mΘlanger les images}
var n,n1,n2,p,p1,p2,ct,ctr :integer;
begin
randomize;form2.visible:=false;Rgledujeu1.enabled:=false;
case radiogroup2.itemIndex of
0:begin cdeb:=2;cfin:=5;ldeb:=2;lfin:=4;ncp:=2;nim:=6;
xdeb:=85;xfin:=430;ydeb:=85;yfin:=345;end;
1:begin cdeb:=2;cfin:=5;ldeb:=1;lfin:=4;ncp:=2;nim:=8;
xdeb:=85;xfin:=430;ydeb:=5;yfin:=345;end;
2:begin cdeb:=2;cfin:=5;ldeb:=1;lfin:=5;ncp:=2;nim:=10;
xdeb:=85;xfin:=430;ydeb:=5;yfin:=425;end;
3:begin cdeb:=1;cfin:=6;ldeb:=1;lfin:=4;ncp:=3;nim:=8;
xdeb:=5;xfin:=510;ydeb:=5;yfin:=345;end;
4:begin cdeb:=1;cfin:=6;ldeb:=1;lfin:=5;ncp:=3;nim:=10;
xdeb:=5;xfin:=510;ydeb:=5;yfin:=425;end;
end;
for n:=1 to 5 do
begin
for p:=1 to 6 do
begin
if (n<ldeb)or (n>lfin)or(p<cdeb)or(p>cfin) then
im[n][p].picture:=fond[0].picture else
im[n][p].picture:=fond[1].picture;
im[n][p].enabled:=false;
end;
end;
ct:=0;
for n:=ldeb to lfin do
begin
for p:=cdeb to cfin do
begin
ct:=ct+1;ctr:=ct mod nim;
cell[n][p]:=ctr;
end;
end;
for n:=1 to 2000 do
begin
n1:=random(lfin+1-ldeb)+ldeb;p1:=random(cfin+1-cdeb)+cdeb;
cell[0][0]:=cell[n1][p1];
n2:=random(lfin+1-ldeb)+ldeb;p2:=random(cfin+1-cdeb)+cdeb;
cell[n1][p1]:=cell[n2][p2];cell[n2][p2]:=cell[0][0];
end;
radiogroup2.enabled:=false;
radiogroup1.enabled:=true;
end;
procedure TForm1.RadioGroup1Click(Sender: TObject);
{choix du nombre de joueurs et de chaque nom}
begin
case radiogroup1.itemIndex of
0:begin nbrej:=1;joueur1.enabled:=true;end;
1:begin nbrej:=2;joueur1.enabled:=true;joueur2.enabled:=true;end;
end;
radiogroup1.enabled:=false;bouton.enabled:=true;
end;
procedure Tform1.fin_jeu;
var n,p :integer;
begin
for n:=1 to 5 do
begin
for p:=1 to 6 do im[n][p].enabled:=true;
end;
statictext6.visible:=true;
Statictext4.caption:=nomj[1]+' : '+intTostr(score[1]);
statictext4.visible:=true;
if nbrej=2 then
begin
Statictext5.caption:=nomj[2]+' : '+intTostr(score[2]);
statictext5.visible:=true;
end;
end;
procedure TForm1.boutonClick(Sender: TObject);
{lancer le jeu et permettre de voir la solution}
var n,p,num :integer;
begin
if bouton.caption=' Jeu!' then
begin
nomj[1]:=joueur1.text;
if nbrej>1 then nomj[2]:=joueur2.text;
statictext1.caption:='Joueur : '+nomj[1];
nessai[1]:=1;nessai[2]:=1;score[1]:=0;score[2]:=0;
statictext2.caption:='Score: '+intTostr(score[1]);
statictext3.caption:='Essai numΘro: '+intTostr(nessai[1]);
bouton.caption:='Solution';panel1.enabled:=true;njeu:=0;nj:=1;
joueur1.enabled:=false;joueur2.enabled:=false;
end
else
begin
for n:=ldeb to lfin do
begin
for p:=cdeb to cfin do
begin
num:=cell[n][p];im[n][p].picture:=anim[num].picture;
im[n][p].visible:=true;im[n][p].enabled:=true;
end;
end;
fin_jeu;
end;
end;
procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
{retourner les 2 ou 3 images suivant le type de jeu choisi}
var n,p,c,cc,l,ll,num :integer;
begin
if (x>xdeb)and(x<xfin)and(y>ydeb)and(y<yfin) then
begin
c:=(x div 85);l:=(y div 85);
if (x-c*85>5) and (y-l*85>5) then
begin
l:=l+1;c:=c+1;lj[njeu]:=l;cj[njeu]:=c;
num:=cell[l][c];im[l][c].picture:=anim[num].picture;
im[l][c].enabled:=true;im[l][c].visible:=true;
njeu:=njeu+1;
end;
end;
ntemp:=0;
if njeu=ncp then
begin
panel1.enabled:=false;timer1.enabled:=true;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
{gestion des images retournΘes: si ce sont les mΩmes :compter des points ,
sinon :retourner les cartes en laissant un peu de temps pour les voir }
var l,c,n,p,q :integer;
gagn :string;
begin
timer1.interval:=1000;
ntemp:=ntemp+1;gagn:='non';
if ntemp=3 then
begin
if ncp=2 then
begin
n:=cell[lj[0]][cj[0]];p:=cell[lj[1]][cj[1]];
if n=p then
begin
if n=0 then score[nj]:=score[nj]+1 else score[nj]:=score[nj]+2;
gagn:='oui';statictext2.caption:='Score: '+intTostr(score[nj]);
if score[1]+score[2]=2*nim-1 then fin_jeu;
end;
end;
if ncp=3 then
begin
n:=cell[lj[0]][cj[0]];p:=cell[lj[1]][cj[1]];q:=cell[lj[2]][cj[2]];
if (n=p) and (n=q) and (p=q) then
begin
if n=0 then score[nj]:=score[nj]+2 else score[nj]:=score[nj]+3;
gagn:='oui';statictext2.caption:='Score: '+intTostr(score[nj]);
if score[1]+score[2]=3*nim-1 then fin_jeu;
end;
end;
if gagn='non' then
begin
for n:=0 to ncp-1 do
begin
l:=lj[n];c:=cj[n];im[l][c].picture:=fond[1].picture;
im[l][c].enabled:=false;
end;
if nj=1 then nessai[1]:=nessai[1]+1 else nessai[2]:=nessai[2]+1;
if (nbrej=2)and (nj=1) then nj:=2 else nj:=1;
statictext1.caption:='Joueur : '+nomj[nj];
statictext2.caption:='Score: '+intTostr(score[nj]);
statictext3.caption:='Essai numΘro: '+intTostr(nessai[nj]);
end;
timer1.enabled:=false;njeu:=0;panel1.enabled:=true;
end;
end;
procedure TForm1.Quitter1Click(Sender: TObject);
begin
form1.close;
end;
procedure TForm1.Recommencer1Click(Sender: TObject);
begin
debut;
end;
procedure TForm1.Rgledujeu1Click(Sender: TObject);
begin
form2.visible:=true;
end;
end.